package top.forforever.srb.core.controller.api;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.forforever.srb.common.result.R;
import top.forforever.srb.core.pojo.entity.Lend;
import top.forforever.srb.core.service.LendService;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author Mr.Jiang
 * @since 2023-04-29
 */
@RestController
@RequestMapping("/api/core/lend")
public class ApiLendController {

    @Autowired
    private LendService lendService;

    @GetMapping("lendList")
    public R getLendList() {
        Page<Lend> page = lendService.getPageList(1, 100000);
        return R.ok().data("lendList", page.getRecords());
    }

    @GetMapping("detail/{lendId}")
    public R detail(@PathVariable Long lendId) {
        Map<String, Object> lendDetail = lendService.getLendDetail(lendId);
        return R.ok().data("lendDetail", lendDetail);
    }

    @GetMapping("getInterestCount/{investAmount}/{returnMethod}/{lendYearRate}/{period}")
    public R getInterestCount(@PathVariable BigDecimal investAmount,
                              @PathVariable Integer returnMethod,
                              @PathVariable BigDecimal lendYearRate,
                              @PathVariable Integer period) {

        BigDecimal interestCount = lendService.getInterestCount(investAmount, returnMethod, lendYearRate, period);
        return R.ok().data("interestCount", interestCount);
    }

}

